package com.ld.campus_help.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ld.campus_help.entity.Serve;
import com.ld.campus_help.entity.Unused;
import com.ld.campus_help.mapper.ServeMapper;
import com.ld.campus_help.mapper.UnusedMapper;
import com.ld.campus_help.service.ServeService;
import com.ld.campus_help.service.UnusedService;
import com.ld.campus_help.util.Result;
import com.ld.campus_help.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/unused")
public class UnusedController {
    @Autowired
    private UnusedMapper unusedMapper;
    @Autowired
    private UnusedService unusedService;

    @Autowired
    private ServeMapper serveMapper;
    @Autowired
    private ServeService serveService;

    @GetMapping("/list")
    public Result getLostList(){
        List<Unused> result = unusedService.getList(1);
        if(result != null) return ResultUtil.success(result);
        return ResultUtil.failure();
    }

    @PostMapping("/statusList")
    public Result getStatusList(@RequestBody Unused unused){
        List<Unused> result = unusedService.getList(unused);
        if (result != null) return ResultUtil.success(result);
        return ResultUtil.failure();
    }

    @GetMapping("deleteUnused")
    public Result deleteUnused(){
        QueryWrapper<Unused> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", 3);
        Unused deleted = unusedService.getOne(queryWrapper);
        if(deleted != null) {
            unusedService.remove(queryWrapper);
            serveService.saveUnused(deleted);
            return ResultUtil.success();
        }
        return ResultUtil.failure();
    }
}
